//index.js
//获取应用实例
const app = getApp()
 const Api = require("../../utils/api.js").API
 const Store = require("../../utils/store.js").store
 const codeZ = require("../../utils/util.js")
Page({
    data: {
       value:'',
       list:[],
       isShow:false,
       heizhi:400,
    },
    onLoad() { 
        
        
    },
    onShow: function() { 
       this.setData({
            heizhi:(app.globalData.screenHeight-240),
           
            
       })
        let that = this;
       
            
            Api.cheakGroupApi().then(res=>{
                if(res.code == 0){                
                    that.setData({
                        list:res.data.groupInfo
                    })
                }
            })
        
       
    },
    clickDe:function(e){ 
       
        let i = e.currentTarget.dataset.inde;
          let j = e.currentTarget.dataset.index;
          var comSta = `list[${i}].recipientInfo[${j}].groupState`;
         let a = this.data.list[i].recipientInfo[j].groupState;
          if(a == null){   
              this.setData({
                    [comSta]:'1'
              })   
          }else{
             this.setData({
                   [comSta]:null
             })
          }     
          console.log(this.data.list);
        // wx.navigateTo({
        //     url: '../shouDaoDetail/index',
        // })
    },
    addSLR:function(){
        wx.navigateTo({
            url: '../adressEdit/index',
        })
    },
    onChangeValue:function(e){
        this.setData({
            value:e.detail
        })
    },
    saveGroup:function(){     
        if(this.data.value == ''){
         return wx.showToast({
        icon: 'none',
        title: '标签名称'
          })
        }
        var ids =[];
        var  arr = this.data.list;
        arr.forEach(item=>{
            var ar = item.recipientInfo;
            if(ar != null){
                ar.forEach(ite=>{
                    if(ite.groupState != null){
                        ids.push(ite['id']);
                    }
                })
            }
          
        })
        
        let data = {
            
            	"ckGroupName": this.data.value,
            	"ids": ids
            
        }
      
        Api.saveGroupPersonApi(data).then(res=>{
              wx.navigateBack();
        })
    }
});
